<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="产品名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="融资企业" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入融资企业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['lendmoney:info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['lendmoney:info:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['lendmoney:info:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['lendmoney:info:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="标识" align="center" prop="code" />
      <el-table-column label="是否删除 1:否 2:是 " align="center" prop="isDelete" />
      <el-table-column label="产品名称" align="center" prop="name" />
      <el-table-column label="贷款产品种类 1:信用贷 2:抵押贷" align="center" prop="kind" />
      <el-table-column label="最低借款额度" align="center" prop="minBorrowing" />
      <el-table-column label="最高借款额度" align="center" prop="maxBorrowing" />
      <el-table-column label="是否循环贷款 1:是 2:否" align="center" prop="isRevolvingLoan" />
      <el-table-column label="借款手续费 1:0.01 2:" align="center" prop="serviceCharge" />
      <el-table-column label="支持期数 1:3期 2:6期 3:12期" align="center" prop="type" />
      <el-table-column label="利率" align="center" prop="interestRates" />
      <el-table-column label="利率单位  1:日 2:月 3:年" align="center" prop="interestRateUnits" />
      <el-table-column label="融资企业" align="center" prop="companyName" />
      <el-table-column label="商业模式 1:自营贷 2:联合贷" align="center" prop="model" />
      <el-table-column label="投资比例" align="center" prop="investmentProportions" />
      <el-table-column label="收益比例" align="center" prop="earningsRatios" />
      <el-table-column label="放款时间 1:及时放款 2:24小时内" align="center" prop="loanTime" />
      <el-table-column label="预警间隔时间" align="center" prop="warningInterval" />
      <el-table-column label="预警间隔时间单位" align="center" prop="warningIntervalUnit" />
      <el-table-column label="逾期利率" align="center" prop="overdueInterestRate" />
      <el-table-column label="支持部分还款的类型 1:提前还款 2:按时还款" align="center" prop="repaymentType" />
      <el-table-column label="部分还款期数 1:1期 2:2期" align="center" prop="partialRepaymentPeriod" />
      <el-table-column label="部分还款比例" align="center" prop="partialRepaymentRatio" />
      <el-table-column label="收益比例" align="center" prop="profitRateRatio" />
      <el-table-column label="是否收取手续费" align="center" prop="isCollectionOfServiceCharge" />
      <el-table-column label="结算手续费" align="center" prop="settlementCharge" />
      <el-table-column label="申请贷款标识" align="center" prop="applyForLoanCode" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['lendmoney:info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['lendmoney:info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改借款信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="标识" prop="code">
          <el-input v-model="form.code" placeholder="请输入标识" />
        </el-form-item>
        <el-form-item label="是否删除 1:否 2:是 " prop="isDelete">
          <el-input v-model="form.isDelete" placeholder="请输入是否删除 1:否 2:是 " />
        </el-form-item>
        <el-form-item label="产品名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="贷款产品种类 1:信用贷 2:抵押贷" prop="kind">
          <el-input v-model="form.kind" placeholder="请输入贷款产品种类 1:信用贷 2:抵押贷" />
        </el-form-item>
        <el-form-item label="最低借款额度" prop="minBorrowing">
          <el-input v-model="form.minBorrowing" placeholder="请输入最低借款额度" />
        </el-form-item>
        <el-form-item label="最高借款额度" prop="maxBorrowing">
          <el-input v-model="form.maxBorrowing" placeholder="请输入最高借款额度" />
        </el-form-item>
        <el-form-item label="是否循环贷款 1:是 2:否" prop="isRevolvingLoan">
          <el-input v-model="form.isRevolvingLoan" placeholder="请输入是否循环贷款 1:是 2:否" />
        </el-form-item>
        <el-form-item label="借款手续费 1:0.01 2:" prop="serviceCharge">
          <el-input v-model="form.serviceCharge" placeholder="请输入借款手续费 1:0.01 2:" />
        </el-form-item>
        <el-form-item label="利率" prop="interestRates">
          <el-input v-model="form.interestRates" placeholder="请输入利率" />
        </el-form-item>
        <el-form-item label="利率单位  1:日 2:月 3:年" prop="interestRateUnits">
          <el-input v-model="form.interestRateUnits" placeholder="请输入利率单位  1:日 2:月 3:年" />
        </el-form-item>
        <el-form-item label="融资企业" prop="companyName">
          <el-input v-model="form.companyName" placeholder="请输入融资企业" />
        </el-form-item>
        <el-form-item label="商业模式 1:自营贷 2:联合贷" prop="model">
          <el-input v-model="form.model" placeholder="请输入商业模式 1:自营贷 2:联合贷" />
        </el-form-item>
        <el-form-item label="投资比例" prop="investmentProportions">
          <el-input v-model="form.investmentProportions" placeholder="请输入投资比例" />
        </el-form-item>
        <el-form-item label="收益比例" prop="earningsRatios">
          <el-input v-model="form.earningsRatios" placeholder="请输入收益比例" />
        </el-form-item>
        <el-form-item label="放款时间 1:及时放款 2:24小时内" prop="loanTime">
          <el-input v-model="form.loanTime" placeholder="请输入放款时间 1:及时放款 2:24小时内" />
        </el-form-item>
        <el-form-item label="预警间隔时间" prop="warningInterval">
          <el-input v-model="form.warningInterval" placeholder="请输入预警间隔时间" />
        </el-form-item>
        <el-form-item label="预警间隔时间单位" prop="warningIntervalUnit">
          <el-input v-model="form.warningIntervalUnit" placeholder="请输入预警间隔时间单位" />
        </el-form-item>
        <el-form-item label="逾期利率" prop="overdueInterestRate">
          <el-input v-model="form.overdueInterestRate" placeholder="请输入逾期利率" />
        </el-form-item>
        <el-form-item label="部分还款期数 1:1期 2:2期" prop="partialRepaymentPeriod">
          <el-input v-model="form.partialRepaymentPeriod" placeholder="请输入部分还款期数 1:1期 2:2期" />
        </el-form-item>
        <el-form-item label="部分还款比例" prop="partialRepaymentRatio">
          <el-input v-model="form.partialRepaymentRatio" placeholder="请输入部分还款比例" />
        </el-form-item>
        <el-form-item label="收益比例" prop="profitRateRatio">
          <el-input v-model="form.profitRateRatio" placeholder="请输入收益比例" />
        </el-form-item>
        <el-form-item label="是否收取手续费" prop="isCollectionOfServiceCharge">
          <el-input v-model="form.isCollectionOfServiceCharge" placeholder="请输入是否收取手续费" />
        </el-form-item>
        <el-form-item label="结算手续费" prop="settlementCharge">
          <el-input v-model="form.settlementCharge" placeholder="请输入结算手续费" />
        </el-form-item>
        <el-form-item label="申请贷款标识" prop="applyForLoanCode">
          <el-input v-model="form.applyForLoanCode" placeholder="请输入申请贷款标识" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/lendmoney/info";

export default {
  name: "Info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 借款信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        companyName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        applyForLoanCode: [
          { required: true, message: "申请贷款标识不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询借款信息列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        code: null,
        isDelete: null,
        name: null,
        kind: null,
        minBorrowing: null,
        maxBorrowing: null,
        isRevolvingLoan: null,
        serviceCharge: null,
        type: null,
        interestRates: null,
        interestRateUnits: null,
        companyName: null,
        model: null,
        investmentProportions: null,
        earningsRatios: null,
        loanTime: null,
        warningInterval: null,
        warningIntervalUnit: null,
        overdueInterestRate: null,
        repaymentType: null,
        partialRepaymentPeriod: null,
        partialRepaymentRatio: null,
        profitRateRatio: null,
        isCollectionOfServiceCharge: null,
        settlementCharge: null,
        applyForLoanCode: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加借款信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改借款信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除借款信息编号为"' + ids + '"的数据项？').then(function() {
        return delInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('lendmoney/info/export', {
        ...this.queryParams
      }, `info_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
